import request from "../utils/request";
const baseURL = "/api";

/**
 * 用户有关的路由规则
 */
// 检测用户名是否存在
export const userNameExist = (data) =>
  request({
    method: "post",
    url: baseURL + "/userExist",
    data,
  });
// 上传新的文章内容
export const register = (data) =>
  request({
    method: "post",
    url: baseURL + "/register",
    data,
  });
// 发送邮箱验证码
export const sendCode = (email) =>
  request({
    method: "post",
    url: baseURL + "/sendCode",
    data: { email },
  });
// 账号密码登录
export const login = (data) =>
  request({
    method: "post",
    url: baseURL + "/login",
    data,
  });
// 邮箱验证登录
export const emailLogin = (data) =>
  request({
    method: "post",
    url: baseURL + "/emailLogin",
    data,
  });
// 根据uuid获取用户信息
export const getUserInfo = (uuid) =>
  request({
    method: "get",
    url: baseURL + `/getUserInfo`,
    params: { uuid },
  });
// 根据id获取目标用户信息
export const getAimUserInfo = (id) =>
  request({
    method: "get",
    url: baseURL + `/getAimUserInfo`,
    params: { id },
  });
// 根据id获取目标用户信息
export const getAllUserInfo = () =>
  request({
    method: "get",
    url: baseURL + `/getAllUserInfo`,
  });
// 获取该用户的所有收藏
export const getUserCollect = (user_id) =>
  request({
    method: "get",
    url: baseURL + `/getUserCollect`,
    params: { user_id },
  });
// 获取该用户的浏览历史
export const getBrowseHistory = ({ user_id }) =>
  request({
    method: "get",
    url: baseURL + `/getBrowseHistory`,
    params: { user_id },
  });

/**
 * 文章有关的路由规则
 */
// 根据id获取文章信息
export const acquire = (id) =>
  request({
    method: "get",
    url: baseURL + `/acquire`,
    params: { article_id: id },
  });
// 获取所有文章信息
export const allArticle = () =>
  request({
    method: "get",
    url: baseURL + "/allArticle",
  });
// 根据用户uuid获取用户其他文章信息
export const getUserArticle = (uuid) =>
  request({
    method: "get",
    url: baseURL + `/getUserArticle`,
    params: { uuid },
  });
// 根据用户uuid获取用户其他文章信息
export const addBrowse = (uuid) =>
  request({
    method: "post",
    url: baseURL + `/addBrowse`,
    data: { uuid },
  });

/**
 * 评论有关的
 */
// 根据文章id获取该篇文章的所有评论
export const gain = (data) =>
  request({
    method: "get",
    url: baseURL + "/gain",
    params: data,
  });

/**
 * 标签有关的路由规则
 */
// 获取标签列表
export const list = () =>
  request({
    method: "get",
    url: baseURL + "/list",
  });

/**
 * 搜索有关的路由规则
 */
export const searchContent = (data) =>
  request({
    method: "get",
    url: baseURL + "/searchContent",
    params: data,
  });

// 将所有内容默认暴露出去
export default {
  userNameExist,
  register,
  searchContent,
  getUserCollect,
  getBrowseHistory,
  addBrowse,
  sendCode,
  gain,
  getAllUserInfo,
  getAimUserInfo,
  acquire,
  allArticle,
  list,
  login,
  emailLogin,
  getUserInfo,
  getUserArticle,
};
